home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / net / netware / nwacct.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-20  |  18.1 KB  |  509 lines

  1. {$X+,V-,B-}
  2. Unit nwAcct;
  3.  
  4. INTERFACE
  5.  
  6. Uses nwMisc,nwBindry,nwConn;
  7.  
  8. { Primary functions:                  Interrupt: Comments:
  9.  
  10. * GetAccountStatus                    (F217/96)  (1)
  11. * SubmitAccountCharge                 (F217/97)  (2)(3)
  12. * SubmitAccountHold                   (F217/98)  (2)
  13. * SubmitAccountNote                   (F217/99)  (2)
  14.  
  15.   Secondary functions:
  16.  
  17. * AccountingInstalled    (4)
  18. * SetAccountStatus       (5)
  19. * AddAccountingServer    (5)
  20. * DeleteAccountingServer (5)
  21. * DeleteAccountHolds     (2)
  22.  
  23.   Notes: (1) To be called by:
  24.              -accounting servers;
  25.              -supervisor equivalent users;
  26.              -objects querying their own account status.
  27.          (2) To be called by accounting servers only.
  28.          (3) Can be imitated by supervisor-equivalent users by
  29.              calling GetAccountStatus and SetAccountStatus. Atomicity
  30.              of such a bindery transaction can not be guaranteed.
  31.          (4) Can be called by all logged on users.
  32.          (5) Supervisor equivalent users only.
  33.  
  34. }
  35.  
  36. Var result:word;
  37.  
  38.  
  39. {F217/96 [2.15c+]}
  40. Function GetAccountStatus(objName:string; objType:word;
  41.                           Var balance,limit,holds:LongInt):boolean;
  42. { equivalent to reading the ACCOUNT_BALANCE and ACCOUNT_HOLDS properties
  43.   of the object. The properties may not exist. }
  44. { !! will only work when the caller is an accounting server !! }
  45.  
  46. {F217/97 [2.15c+]}
  47. Function SubmitAccountCharge(objName:string; objType:word;
  48.                              charge,cancelHoldAmount:Longint;
  49.                              serviceType, commentType:word; comment:string):boolean;
  50. { -The cancelHold amount should be exactly the same as the amount that
  51.    was put on huld with the SubmitAccountHold call. If no
  52.    SubmitAccountHold call was made, the cancelHoldAmount should be set to zero.
  53.   -'negative charges' are allowed. They will increase the balance of
  54.    the object objName of objType.
  55.   -Use the objectType of caller for the serviceType parameter.
  56.    (audit log purposes)
  57.   -Set commentType to 0 and comment to '' if you aren't interested in the
  58.    audit log. }
  59.  
  60. {F217/98 [2.15c+]}
  61. Function SubmitAccountHold(objName:string; objType:word;
  62.                            reserveAmount:Longint         ):boolean;
  63.  
  64. {F217/99 [2.15c+]}
  65. Function SubmitAccountNote(objName:string; objType:word;
  66.                            serviceType,commentType:word; comment:string):boolean;
  67.  
  68. {--------Secondary Functions-----------------------------------------------}
  69.  
  70. Function AccountingInstalled:boolean;
  71. Function SetAccountStatus(objName:string; objType:word; balance,limit:LongInt):boolean;
  72. { need to be supervisor equivalent to use this call }
  73. Function AddAccountingServer(objName:string;objType:word):boolean;
  74. { need to be supervisor equivalent to use this call }
  75. Function DeleteAccountingServer(objName:string;objType:word):boolean;
  76. { need to be supervisor equivalent to use this call }
  77. Function DeleteAccountHolds(objName:string; objType:word):boolean;
  78. { delete all holds the caller (an accounting server) has on the
  79.   object with name objName of type objType. }
  80.  
  81. Type Tcharge=record
  82.              DaysOfCharge:Byte; { bit 0=sunday,.. bit 6=saturday }
  83.              TimeOfCharge:Byte; { 0:00=0 ..23:30 =47, half-hour
  84.                                   during which the specified 'new' rate takes effect. }
  85.              ChargeRateMultiplier,
  86.              ChargeRateDivisor:Word;
  87.              end;
  88.      TchargeRec=record
  89.                 NextChargeTime:Longint; { minutes since 1-1-1985 }
  90.                 charges:array[1..20] of Tcharge;
  91.                 end;
  92.  
  93.  
  94. Type TchargeTableEntry=array[0..47] of Real;
  95. Var ChargeTable:Array [0..6] of TchargeTableEntry;
  96.  
  97. IMPLEMENTATION {===========================================================}
  98.  
  99. USES Dos;
  100.  
  101. Var UnitReqBuffer:array[1..576] of byte;
  102.     UnitReplyBuffer:array[1..576] of byte;
  103.     UnitRegs:registers;
  104.  
  105. Procedure F2SystemCall(subf:byte;req_size,rep_size:word);
  106. begin
  107. With UnitRegs
  108.  do begin
  109.     DS := Seg(UnitReqBuffer);  SI := Ofs(UnitReqBuffer);   CX := Req_size;
  110.     ES := Seg(UnitReplyBuffer);DI := Ofs(UnitReplyBuffer); DX := rep_size;
  111.     AH := $F2; AL := subf;
  112.     MSDOS(UnitRegs);
  113.     Result:=al;
  114.     end;
  115. end;
  116.  
  117. Procedure GetBindryAccountStatus(objName:string; objType:word;
  118.                                 Var balance,limit,holds:LongInt);
  119. { called by GetAccountStatus when the calling object isn't an
  120.   accounting server. The F217/96 fails, but a bindery read will
  121.   work for supervisor-equivalent users. }
  122. Var accPropVal:propertyType;
  123.     accVal: record
  124.             _balance:LongInt; {hi-lo}
  125.             _limit:LongInt;   {hi-lo}
  126.             _Reserved:array[1..120] of byte; { NW internal info }
  127.             end ABSOLUTE accPropVal;
  128.     holdPropVal:propertyType;
  129.     holdVal: array[1..16]
  130.               of record
  131.                  AccountServerID:Longint; {hi-lo}
  132.                  HoldAmount     :LongInt; {hi-lo}
  133.                  end ABSOLUTE holdPropVal;
  134.     moreSegments:boolean;
  135.     t,propFlags:byte;
  136. begin
  137. IF ReadPropertyValue(objName,objType,'ACCOUNT_BALANCE',1,
  138.                     accPropVal,moreSegments,propFlags)
  139.   then begin
  140.        balance:=Lswap(accVal._balance);
  141.        limit:=Lswap(accVal._limit);
  142.        IF ReadPropertyValue(objName,objType,'ACCOUNT_HOLDS',1,
  143.                             holdPropVal,moreSegments,propFlags)
  144.         then begin { holds exist. }
  145.              holds:=0;
  146.              for t:=1 to 16
  147.               do if holdVal[t].AccountServerID<>0
  148.                  then holds:=holds+Lswap(holdVal[t].HoldAmount);
  149.              end;
  150.        if nwBindry.result=$FB
  151.          then begin
  152.               result:=0;
  153.               holds:=0;
  154.               end
  155.          else result:=nwBindry.result;
  156.        end
  157.   else if nwBindry.result=$FB { no such property }
  158.         then result:=$C1
  159.         else if nwBindry.result=$F1 { invalid bindery security }
  160.              then result:=$C0
  161.              else result:=nwBindry.result;
  162. { resultcodes: 00 success; C0 No Account Privileges; C1 No Account Balance;
  163.   96 Server Out Of memory; FC No Such Object; FE Server Bindery Locked;
  164.   FF Bindery Failure}
  165. end;
  166.  
  167.  
  168. {F217/96 [2.15c+]}
  169. Function GetAccountStatus(objName:string; objType:word;
  170.                           Var balance,limit,holds:LongInt):boolean;
  171. { equivalent to reading the ACCOUNT_BALANCE and ACCOUNT_HOLDS properties
  172.   of the object. The properties may not exist. }
  173. { This function will be successfull if:
  174.      a) the caller is an accounting server on the current fileserver
  175.   OR b) the caller is supervisor-equivalent
  176.   OR c) the caller is querying his own account status }
  177. var req:record
  178.         len:word;
  179.         subF:byte;
  180.         _objType:word; {hi-lo}
  181.         _objName:string[48];
  182.         end                   ABSOLUTE UnitReqBuffer;
  183.     reply:record
  184.           _balance: LongInt; {hi-lo}
  185.           _limit  : Longint; {hi-lo}
  186.           reserved: array [1..120] of byte;
  187.           _holds  : array [1..16]
  188.                      of record
  189.                         serverObjId:LongInt; {hi-lo}
  190.                         HoldAmount :LongInt  {hi-lo}
  191.                         end;
  192.           end                 ABSOLUTE UnitReplyBuffer;
  193.     t:byte;
  194. begin
  195. With req
  196.  do begin
  197.     len:=sizeOf(req)-2;
  198.     subf:=$96;
  199.     _objType:=swap(objType); { force hi-lo}
  200.     PstrCopy(_objName,objName,48); UpString(_objName);
  201.     end;
  202. F2SystemCall($17,sizeOf(req),sizeOf(reply));
  203. With reply
  204.  do begin
  205.     balance:=Lswap(_balance); { force lo-hi again }
  206.     limit:=Lswap(_limit); { force lo-hi again }
  207.     holds:=0;
  208.     for t:=1 to 16
  209.      do if _holds[t].serverObjId<>0
  210.       then holds:=holds+Lswap(_holds[t].holdAmount); { force lo-hi again }
  211.     end;
  212. IF result=$C0 { no account privileges }
  213.  then GetBindryAccountStatus(objName,objType,balance,limit,holds);
  214.       { try to read status not as an accounting server, but as a supervisor }
  215. GetAccountStatus:=(result=0);
  216. { resultcodes: 00 success; C0 No Account Privileges; C1 No Account Balance }
  217. end;
  218.  
  219.  
  220. {F217/97 [2.15c+]}
  221. Function SubmitAccountCharge(objName:string; objType:word;
  222.                              charge,cancelHoldAmount:Longint;
  223.                              serviceType, commentType:word; comment:string):boolean;
  224. { -The cancelHold amount should be exactly the same as the amount that
  225.    was put on huld with the SubmitAccountHold call. If no
  226.    SubmitAccountHold call was made, the cancelHoldAmount should be set to zero.
  227.   -'negative charges' are allowed. They will increase the balance of
  228.    the object objName of objType.
  229.   -Use the objectType of caller for the serviceType parameter.
  230.    (audit log purposes)
  231.   -Set commentType to 0 and comment to '' if you aren't interested in the
  232.    audit log.
  233.   -To be called by accounting servers only.
  234.   -Can be imitated by supervisor-equivalent users by
  235.    calling GetAccountStatus and SetAccountStatus. Atomicity
  236.    of such a bindery transcation can not be guaranteed.
  237.  
  238.    }
  239. Var req:record
  240.         len :word;
  241.         subf:byte;
  242.         _serviceType:word;    {hi-lo}
  243.         _charge     :Longint; {hi-lo}
  244.         _cancelHold :Longint; {hi-lo}
  245.         _objType    :word;    {hi-lo}
  246.         _commentType:word;    {hi-lo}
  247.         _objNameAndComment:Array[1..305] of char;
  248.         end                ABSOLUTE UnitReqBuffer;
  249.     p:byte;
  250. begin
  251. With req
  252. do begin
  253.    subf:=$97;
  254.    _serviceType:= swap(serviceType);      {force hi-lo}
  255.    _charge     :=Lswap(charge);           {force hi-lo}
  256.    _cancelHold :=Lswap(cancelHoldAmount); {force hi-lo}
  257.    _objType    := swap(objType);          {force hi-lo}
  258.    _commentType:= swap(commentType);      {force hi-lo}
  259.    p:=ord(objName[0]);if p>48 then p:=48;
  260.    UpString(objName);
  261.    Move(objname[0],_objNameandComment[1],p+1);
  262.    Move(comment[0],_objNameandComment[p+2],ord(comment[0])+1);
  263.    len:=15+p+1+ord(comment[0])+1;
  264.    end;
  265. F2SystemCall($17,req.len+2,0);
  266. SubmitAccountCharge:=(result=$00);
  267. { resultcodes: 00 successfull; C0 No Account Privileges;
  268.                C1 No Account Balance; C2 Credit Limit Exceeded. }
  269. end;
  270.  
  271.  
  272. {F217/98 [2.15c+]}
  273. Function SubmitAccountHold(objName:string; objType:word;
  274.                            reserveAmount:Longint         ):boolean;
  275. { To be called by accounting servers only. }
  276. Var req:record
  277.         len :word;
  278.         subf:byte;
  279.         _reserveAmount:Longint; {hi-lo}
  280.         _objType:word; {hi-lo}
  281.         _objName:string[48];
  282.         end                ABSOLUTE UnitReqBuffer;
  283.    p:byte;
  284. begin
  285. With req
  286. do begin
  287.    subf:=$98;
  288.    _reserveAmount:=Lswap(ReserveAmount); { force hi-lo}
  289.    _objType:=swap(objType); { force hi-lo }
  290.    p:=ord(objName[0]); if p>48 then p:=48;
  291.    _objName:=objname;UpString(_objName);_objName[0]:=chr(p);
  292.    len:=7+p+1;
  293.    end;
  294. F2SystemCall($17,req.len+2,0);
  295. SubmitAccountHold:=(result=$00);
  296. { resultcodes: 00 successfull; C0 No Account Privileges;
  297.                C1 No Account Balance; C2 Credit Limit Exceeded.
  298.                C3 Account Too Many Holds }
  299. end;
  300.  
  301. {F217/99 [2.15c+]}
  302. Function SubmitAccountNote(objName:string; objType:word;
  303.                            serviceType,commentType:word; comment:string):boolean;
  304. { To be called by accounting servers only.}
  305. Var req:record
  306.         len:word;
  307.         subf:byte;
  308.         _serviceType:word; {hi-lo}
  309.         _objType:word; {hi-lo}
  310.         _commentType:word; {hi-lo}
  311.         _objNameAndComment:array[1..305] of char;
  312.         end               ABSOLUTE UnitReqBuffer;
  313.    p:byte;
  314. begin
  315. with req
  316. do begin
  317.    subf:=$99;
  318.    _serviceType:= swap(serviceType);      {force hi-lo}
  319.    _objType    := swap(objType);          {force hi-lo}
  320.    _commentType:= swap(commentType);      {force hi-lo}
  321.    p:=ord(objName[0]);if p>48 then p:=48;
  322.    UpString(objName);
  323.    Move(objname[0],_objNameandComment[1],p+1);
  324.    Move(comment[0],_objNameandComment[p+2],ord(comment[0])+1);
  325.    len:=7+p+1+ord(comment[0])+1;
  326.    end;
  327. F2SystemCall($17,req.len+2,0);
  328. SubmitAccountNote:=(result=0);
  329. {resultcodes: 00 Successful; C0 No Account Privileges }
  330. end;
  331.  
  332. {---------------- Secondary Functions--------------------------------------}
  333.  
  334.  
  335. Function AccountingInstalled:boolean;
  336. Var propVal:propertyType;
  337.     connId:byte;
  338.     moreSegments:boolean;
  339.     propFlags:byte;
  340.     currServerName:string;
  341. begin
  342. IF NOT GetEffectiveConnectionID(ConnId)
  343.   then result:=nwConn.result
  344.   else if NOT GetFileServerName(ConnId,currServerName)
  345.         then result:=nwConn.result
  346.         else begin
  347.              ReadPropertyValue(currServerName,OT_FILE_SERVER,'ACCOUNT_SERVERS',1,
  348.                                propVal,moreSegments,propFlags);
  349.              result:=nwBindry.result;
  350.              end;
  351. AccountingInstalled:=(result=0);
  352. end;
  353.  
  354.  
  355. Function SetAccountStatus(objName:string; objType:word; balance,limit:LongInt):boolean;
  356. { will change the account status to reflect the given parameters.
  357.   any holds will not be changed.
  358.   You need to be supervisor-eq. to do this...}
  359. Var accPropVal:propertyType;
  360.     accVal: record
  361.             _balance:LongInt; {hi-lo}
  362.             _limit:LongInt;   {hi-lo}
  363.             _Reserved:array[1..120] of byte; { NW internal info }
  364.             end ABSOLUTE accPropVal;
  365.     OldBalance,OldLimit,OldHolds:LongInt;
  366.     moreSegments:boolean;
  367.     propFlags:byte;
  368. begin
  369. IF ReadPropertyValue(objName,objType,'ACCOUNT_BALANCE',1,
  370.                     accPropVal,moreSegments,propFlags)
  371.   then begin
  372.        accVal._balance:=Lswap(balance); { force hi-lo}
  373.        accVal._limit:=Lswap(limit); { force hi-lo}
  374.        WritePropertyValue(objName,objType,'ACCOUNT_BALANCE',
  375.                           1,accPropVal,FALSE);
  376.        if (nwBindry.result=$F1) or (nwBindry.result=$F8)
  377.          then result:=$C0
  378.          else result:=nwBindry.result;
  379.        end
  380.   else if nwBindry.result=$FB { no such property }
  381.         then result:=$C1
  382.         else if nwBindry.result=$F1 { invalid bindery security }
  383.              then result:=$C0
  384.              else result:=nwBindry.result;
  385. SetAccountStatus:=(result=$00);
  386. { resultcodes: 00 success; C0 No Account Privileges; C1 No Account Balance;
  387.   96 Server Out Of memory; FC No Such Object; FE Server Bindery Locked;
  388.   FF Bindery Failure}
  389. end;
  390.  
  391.  
  392. Function AddAccountingServer(objName:string;objType:word):boolean;
  393. Var ConnId:byte;
  394.     currServerName:string;
  395. begin
  396. IF NOT GetEffectiveConnectionID(ConnId)
  397.    then result:=nwConn.result
  398.    else if NOT GetFileServerName(ConnId,currServerName)
  399.            then result:=nwConn.result
  400.            else begin
  401.                 AddBinderyObjectToSet(currServerName,OT_FILE_SERVER,'ACCOUNT_SERVERS',
  402.                                       objName,objType);
  403.                 result:=nwBindry.result;
  404.                 end;
  405. AddAccountingServer:=(result=0);
  406. end;
  407.  
  408. Function DeleteAccountingServer(objName:string;objType:word):boolean;
  409. Var ConnId:byte;
  410.     currServerName:string;
  411. begin
  412. IF NOT GetEffectiveConnectionID(ConnId)
  413.    then result:=nwConn.result
  414.    else if NOT GetFileServerName(ConnId,currServerName)
  415.            then result:=nwConn.result
  416.            else begin
  417.                 DeleteBinderyObjectFromSet(currServerName,OT_FILE_SERVER,'ACCOUNT_SERVERS',
  418.                                            objName,objType);
  419.                 result:=nwBindry.result;
  420.                 end;
  421. DeleteAccountingServer:=(result=0);
  422. end;
  423.  
  424. Function DeleteAccountHolds(objName:string; objType:word):boolean;
  425. { delete all holds the caller (an accounting server) has on the
  426.   object with name objName of type objType. }
  427. var req:record
  428.         len:word;
  429.         subF:byte;
  430.         _objType:word; {hi-lo}
  431.         _objName:string[48];
  432.         end                   ABSOLUTE UnitReqBuffer;
  433.     reply:record
  434.           _balance: LongInt; {hi-lo}
  435.           _limit  : Longint; {hi-lo}
  436.           reserved: array [1..120] of byte;
  437.           _holds  : array [1..16]
  438.                      of record
  439.                         serverObjId:LongInt; {hi-lo}
  440.                         HoldAmount :LongInt  {hi-lo}
  441.                         end;
  442.           end                 ABSOLUTE UnitReplyBuffer;
  443.     t:byte;
  444.     holds:LongInt;
  445.     level:byte;
  446.     accServerId:LongInt;
  447.     accServerType:word;
  448.     accServerName:string;
  449. begin
  450. GetBinderyAccessLevel(Level,accServerID);
  451. GetBinderyObjectName(accServerID,accServerName,accServerType);
  452. With req
  453.  do begin
  454.     len:=sizeOf(req)-2;
  455.     subf:=$96;
  456.     _objType:=swap(objType); { force hi-lo}
  457.     PstrCopy(_objName,objName,48); UpString(_objName);
  458.     end;
  459. F2SystemCall($17,sizeOf(req),sizeOf(reply));
  460. if result=0
  461.  then With reply
  462.       do begin
  463.          holds:=0;
  464.          for t:=1 to 16
  465.           do if accServerID=Lswap(_holds[t].serverObjId)
  466.            then holds:=holds+Lswap(_holds[t].holdAmount); { force lo-hi again }
  467.          if holds<>0
  468.           then SubmitAccountCharge(objName,objType,0,holds,
  469.                                    accServerType,0,'clearing holds');
  470.          end;
  471. DeleteAccountHolds:=(result=0);
  472. { resultcodes: 00 success; C0 No Account Privileges; C1 No Account Balance }
  473. end;
  474.  
  475.  
  476. Function GetConnectTimeCharge(Var currentCharge:Real;Var chargeRec:TchargeRec):boolean;
  477. Var propVal:propertyType;
  478.     _chargeRec:TchargeRec             ABSOLUTE propVal;
  479.     _currcharge:record
  480.                 fill:LongInt;
  481.                 currMult,currDiv:word; {hi-lo}
  482.                 end                   ABSOLUTE propVal;
  483.     connId:byte;
  484.     moreSegments:boolean;
  485.     propFlags:byte;
  486.     currServerName:string;
  487. begin
  488. IF NOT GetEffectiveConnectionID(ConnId)
  489.    then result:=nwConn.result
  490.    else if NOT GetFileServerName(ConnId,currServerName)
  491.            then result:=nwConn.result
  492.            else if ReadPropertyValue(currServerName,OT_FILE_SERVER,
  493.                                      'CONNECT_TIME',1,
  494.                                      propVal,moreSegments,propFlags)
  495.                 then begin
  496.                      IF _currCharge.currDiv=0
  497.                       then currentCharge:=0
  498.                       else currentCharge:=Swap(_currCharge.currMult)/Swap(_currCharge.currDiv);
  499.                      move(propVal[9],propVal[5],124);
  500.                      chargeRec:=_chargeRec;
  501.                      result:=0;
  502.                      end
  503.                 else result:=nwBindry.result;
  504. GetConnectTimeCharge:=(result=0);
  505. end;
  506.  
  507.  
  508.  
  509. end.